package es.deusto.ingenieria.aike.time;

import java.util.List;

import es.deusto.ingenieria.aike.csp.formulation.Constraint;
import es.deusto.ingenieria.aike.csp.formulation.Variable;

public class Equation extends Constraint<Integer> {
	
	private Environment env;

	public Equation(List<Variable<Integer>> variables, String name, Environment env){
		super(name, variables);
		this.env = env;
	}

	public boolean isSatisfied(Variable<Integer> variable, Integer value) {
		
		for(Variable<Integer> varAux : this.getVariables())
			if (varAux.getValue() == null && varAux.getName() != variable.getName())
			{
				return true;
			}
			
		int a = 0;int b = 0;int c = 0;int d = 0;
		int e = 0;int f = 0;int g = 0;
		
		if (this.getVariables().get(0).hasValue())
			a = this.getVariables().get(0).getValue();
		else
			a = value;
		if (this.getVariables().get(1).hasValue())
			b = this.getVariables().get(1).getValue();
		else
			b = value;
		if (this.getVariables().get(2).hasValue())
			c = this.getVariables().get(2).getValue();
		else
			c = value;
		if (this.getVariables().get(3).hasValue())
			d = this.getVariables().get(3).getValue();
		else
			d = value;
		if (this.getVariables().get(4).hasValue())
			e = this.getVariables().get(4).getValue();
		else
			e = value;
		if (this.getVariables().get(5).hasValue())
			f = this.getVariables().get(5).getValue();
		else
			f = value;
		if (this.getVariables().get(6).hasValue())
			g = this.getVariables().get(6).getValue();
		else
			g = value;
		
		int x1 = ((c*10+d)* env.getMultiplier())/60;
		
		if ((e*10+f == (a*10+b)*env.getMultiplier()+x1) &&
			((c*10+d) * env.getMultiplier() == (g*10+env.getConstant()) + x1*60))
				return true;
		return false;
	}
}